//
//  YMCheckCameraStatusVC.m
//  YMMedical
//
//  Created by y s on 2023/9/7.
//

#import "YMCheckCameraStatusVC.h"
#import "YMSamplePrepareCameraVC.h"
#import "YMSampleCameraAgainVC.h"

@interface YMCheckCameraStatusVC ()

@property (nonatomic, strong) YMSamplePrepareCameraVC *vcPre;

@property (nonatomic, strong) YMSampleCameraAgainVC *vcAgain;

@property (nonatomic, strong) YMBaseViewController *vcCurrent;

@end

@implementation YMCheckCameraStatusVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [SNavUtil rightIcon:self icon:@"tools_nav_home_icon" onClick:^{
        [YMBridging goHomeTabWithAlert];
    }];
    [self changeStatus:NO];
}

- (void)changeStatus:(BOOL)cameraAgain{
    if (_vcCurrent){
        [_vcCurrent.view removeFromSuperview];
        [_vcCurrent removeFromParentViewController];
        _vcCurrent = nil;
        _vcPre = nil;
        _vcAgain = nil;
    }
    if (cameraAgain){
        [self showNavTitle:KLanguage(@"re_camera_txt")];
        self.vcAgain.checkModel = self.checkModel;
        _vcCurrent = self.vcAgain;
    }else{
        [self showNavTitle:KLanguage(@"prepare_take_photo_txt")];
        self.vcPre.checkModel = self.checkModel;
        _vcCurrent = self.vcPre;
    }
    [self addChildViewController:self.vcCurrent];
    [self.view addSubview:self.vcCurrent.view];
    [self.vcCurrent.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}

#pragma mark -- setter and getter
- (YMSamplePrepareCameraVC *)vcPre{
    if (_vcPre == nil){
        _vcPre = [[YMSamplePrepareCameraVC alloc] init];
        WEAK_SELF;
        _vcPre.finishBlock = ^(NSString * _Nonnull detectionId) {
            if (detectionId == nil || detectionId.length < 1){
                [weakSelf changeStatus:YES];
            }else{
                [YMBridging goToHealthTestReportVC:YES detectionId:detectionId target:weakSelf];
            }
        };
    }
    return _vcPre;
}
- (YMSampleCameraAgainVC *)vcAgain{
    if (_vcAgain == nil){
        _vcAgain = [[YMSampleCameraAgainVC alloc] init];
        WEAK_SELF;
        _vcAgain.finishBlock = ^(NSString * _Nonnull detectionId) {
            if (detectionId != nil && detectionId.length > 0){
                [YMBridging goToHealthTestReportVC:YES detectionId:detectionId target:weakSelf];
            }
        };
    }
    return _vcAgain;
}

@end
